#include<iostream>
using namespace std;

int tile = 0;
int Board[40][40];

//左上角坐标(tr,tc) 黑子坐标(dr,dc) 棋盘规模size
void ChessBoard(int tr,int tc,int dr,int dc,int size);

int main(){
    Board[3][3] = -1;
    ChessBoard(0,0,3,3,8);
    for(int i=0; i<8; i++){
        for(int j=0; j<8; j++){
            cout << Board[i][j] << "\t";
        }
        cout << endl;
    }
    return 0;
}

void ChessBoard(int tr,int tc,int dr,int dc,int size)
{
    if(size == 1){
        return;
    }
    //当前骨牌编号
    int t = tile++;
    //分割后棋盘大小
    int s = size/2;
    //左上角棋盘
    if(dr < tr + s && dc < tc + s){
        //黑子在左上角
        ChessBoard(tr,tc,dr,dc,s);
    }else{
        //黑子不在左上角 右下角放黑子
        Board[tr+s-1][tc+s-1] = t;
        ChessBoard(tr,tc,tr+s-1,tc+s-1,s);
    }
    //右上角棋盘
    if(dr < tr + s && dc >= tc + s){
        //黑子在右上角
        ChessBoard(tr,tc+s,dr,dc,s);
    }else{
        //黑子不在右上角 左下角放黑子
        Board[tr+s-1][tc+s] = t;
        ChessBoard(tr,tc+s,tr+s-1,tc+s,s);
    }
    //左下角棋盘
    if(dr >= tr + s && dc < tc + s){
        //黑子在左下角
        ChessBoard(tr+s,tc,dr,dc,s);
    }else{
        //黑子不在左下角 右上角放黑子
        Board[tr+s][tc+s-1] = t;
        ChessBoard(tr+s,tc,tr+s,tc+s-1,s);
    }
    //右下角棋盘
    if(dr >= tr + s && dc >= tc + s){
        //黑子在右下角
        ChessBoard(tr+s,tc+s,dr,dc,s);
    }else{
        //黑子不在右下角 左上角放黑子
        Board[tr+s][tc+s] = t;
        ChessBoard(tr+s,tc+s,tr+s,tc+s,s);
    }
}